package com.excilys.capicsoubank.webservices.soap.impl;

import java.util.ArrayList;
import java.util.List;

import javax.jws.WebService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.excilys.capicsoubank.dto.AccountDTO;
import com.excilys.capicsoubank.entities.Account;
import com.excilys.capicsoubank.services.AccountService;
import com.excilys.capicsoubank.webservices.soap.UserWebService;

@Component("userWebServiceImpl")
@WebService(endpointInterface = "com.excilys.capicsoubank.webservices.soap.UserWebService")
public class UserWebServiceImpl implements UserWebService {

	@Autowired
	private AccountService accountService;

	@Override
	public List<AccountDTO> getAccounts() {
		List<AccountDTO> accounts = new ArrayList<AccountDTO>();

		for (Account account : accountService.getAccountsConnectedUser())
			accounts.add(new AccountDTO.Builder()
					.accountId(account.getAccountId())
					.label(account.getLabel()).balance(account.getBalance())
					.build());

		return accounts;
	}
}
